package com.lj.edu.web.controller;


import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.lj.edu.model.User;
import com.lj.edu.service.IUserService;
import com.lj.edu.web.controller.base.BaseController;




@Controller
@RequestMapping("/user")
public class UserController extends BaseController<User>{
	
	@Autowired
	protected IUserService userService;

	@RequestMapping("/login")
	public String login() {
		
		System.out.println("登陆成功");
		
		return "Default";
	}
	
	@RequestMapping("/find")
	public String find(Integer id) {
		
		User user = userService.findById(id);
		
		
		System.out.println(user);
		
		
		return null;
	}
	
	@RequestMapping(value = Manage)
	public String manager() {
		
 		
		return Manage_Page;
	}
	
	@RequestMapping(value = Info)
	public String userinfo(Model model) {
		
		ArrayList<User> userlist = (ArrayList<User>) userService.selectAll();
		
		
		
		System.out.println("__________AllUser__________查询数据成功");
		
		for (User user : userlist) {
			
			System.out.println(user.toString());
		}
		
		//向jsp 存取数据
		model.addAttribute("users",userlist);
		
		
		return Info_Page;
	}
	@RequestMapping(value = Edit)
	public String useredit() {
		
		
		return Edit_Page;
	}
	@RequestMapping("/userupdate")
	public String userUpdate() {
		
		
		return "user/pdate";
	}
	
	@RequestMapping("/saveuser")
	public String saveuser(User user) {
		
		
		 userService.insert(user);
		 
		 System.out.println(user);
		 System.out.println("数据保存成功");
		
		 
		return Info_Page;
	}
	
}
